<template>
  <view class="demo">
    <ss-select-city  v-show="!searched" :hotCitys="hotCitys" v-model="value" @on-select="onSelect"></ss-select-city>
  </view>
</template>

<script>
  import ssSelectCity from '@/components/ss-select-city/ss-select-city.vue'
  import {
  	mapState,  
  	mapMutations
  } from 'vuex';
  export default {
    data() {
      return {
        hotCitys: ['银川', '天津', '北京', '秦皇岛', '太原', '湖南', '郑州', '石家庄', '济南'],
        value: uni.getStorageSync('city'),
		searched: false,
		keyword: ''
      }
    },
	onNavigationBarSearchInputChanged(e) {
		console.log('用户输入搜索框:', e)
		this.searched = true; 
	},
	onNavigationBarSearchInputConfirmed(e) {
		console.log('用户点击搜索按钮:', e)
		this.doSearch(e.text)
	},
	methods:{
		doSearch(key) {
			this.keyword = key;
			this.saveKeyword(key); //保存为历史 
			//#ifdef H5
			goodsApis.searchWord(key).then(res => {
				this.searched = true;
				this.goodsList = res;
			})
			//#endif
		},
		onSelect(city) {
		  this.$emit('input', city)
		  this.$emit('on-select', city)
		  this.changeCity(city)
		},
		...mapMutations({
			'changeCity': 'CHANGE_CITY'
		})
	},
    components: {
      ssSelectCity
    }
  }
</script>

<style scoped>

</style>
